package com.mall.xiaomi.controller;

import com.mall.xiaomi.pojo.Product;
import com.mall.xiaomi.service.CollectService;
import com.mall.xiaomi.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhanggaoxiang
 * @ClassName CollectController
 * @Description TODO
 * @Date 2021/2/24 20:45
 * @Version 1.0
 **/
@RestController
@RequestMapping("/collect")
public class CollectController {
    @Autowired
    private ResultMessage resultMessage;
    @Autowired
    private CollectService collectService;

    @GetMapping("/user/{userId}")
    public ResultMessage getCollectByUid(@PathVariable("userId") Integer userId) {
        List<Product> list = collectService.getCollectByUid(userId);
        resultMessage.success("001", list);
        return resultMessage;
    }

    @DeleteMapping("/user/{productId}/{userId}")
    public ResultMessage delCollectById(@PathVariable("productId") Integer productId, @PathVariable("userId") Integer userId) {
        collectService.delCollectById(productId, userId);
        resultMessage.success("001", "删除成功");
        return resultMessage;
    }

    @PostMapping("/user/{productId}/{userId}")
    public ResultMessage addCollect(@PathVariable("productId") Integer productId, @PathVariable("userId") Integer userId){
        collectService.addCollect(productId,userId);
        resultMessage.success("001", "添加成功");
        return resultMessage;
    }

}
